package com.hyjx.framework.service;

import com.hyjx.framework.common.util.SpringBeanUtil;
import com.hyjx.framework.service.session.ISession;

import javax.servlet.http.HttpServletRequest;

/**
 * 基础session服务
 *
 * @author Peter
 */
public class SessionManager {
    private static final ISession cache;
    
    static {
        String config = ConfigManager.getConfig("hyjx.session.type", "baseSession");
        cache = (ISession) SpringBeanUtil.getBean(config);
    }
    
    /**
     * 设置Session对象
     *
     * @param key
     * @param value
     */
    public static void set(String key, Object value) {
        cache.set(key, value);
    }
    
    public static void setByRequest(HttpServletRequest request, String key, Object value) {
        cache.setByRequest(request, key, value);
    }
    
    /**
     * 强制设置Session对象
     *
     * @param key
     * @param value
     */
    public static void forceSet(String key, Object value) {
        cache.forceSet(key, value);
    }
    
    /**
     * 获取Session对象
     *
     * @param key
     */
    public static Object get(String key) {
        Object obj = cache.get(key);
        return obj;
    }
    
    /**
     * 移除Session对象
     *
     * @param key
     */
    public static void remove(String key) {
        cache.remove(key);
    }
    
    /**
     * 取Session对象
     *
     * @param key
     */
    public static String getString(String key) {
        return cache.getString(key);
    }
    
    /**
     * Session失效
     */
    public static void invalidate() {
        cache.invalidate();
    }
}